package com.jason.happy.module.framework;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.jason.happy.common.framework.BaseLogicView;
import com.jason.happy.common.framework.BaseLogicPresenter;

import org.xutils.x;

/**
 * Created by hacker on 17-6-25.
 */

public abstract class BaseMVPActivity<V extends BaseLogicView, T extends BaseLogicPresenter<V>> extends AppCompatActivity implements BaseLogicView {

    protected T mLogicPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLogicPresenter = createPresenter();
        mLogicPresenter.attachView((V) this);
        setContentView(getContentView());

        x.view().inject(this);

        initWeight(savedInstanceState);
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLogicPresenter.removeView();
    }

    public abstract T createPresenter();

    public abstract void initWeight(Bundle savedInstanceState);

    public abstract int getContentView();

}
